<?php

namespace App\Kuafu\Mybank\Service\CalcBrokerage;

use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\Mybank\Model\MybankBillRecordModel;
use App\Kuafu\Mybank\Model\MybankEntryModel;
use App\Kuafu\Mybank\Model\MybankShopBindModel;
use App\Kuafu\Order\Model\OrderSplitModel;
use App\Kuafu\Shop\Model\Shop;
use App\Kuafu\Shop\Resources\B\ShopSimpleResource;
use App\Kuafu\Shop\Service\ShopService;
use App\Kuafu\WaiMai\Model\WaiMaiOrderModel;
use App\Scope\ShopScope;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;

abstract class MybankCalcBrokerageService
{
    protected int $shopId;

    protected string $orderId;

    protected int $brokerage;

    protected string $brokeragePer;

    protected int $divisionBillId;

    public function __construct($shopId = 0, string $orderId = '')
    {
        $this->shopId  = $shopId;
        $this->orderId = $orderId;

//        $this->calcBrokerage();
    }

    /**
     * @return int
     */
    public function getBrokerage(): int
    {
        return $this->brokerage;
    }

    /**
     * @param int $brokerage
     */
    public function setBrokerage(int $brokerage): void
    {
        $this->brokerage = $brokerage;
    }

    /**
     * @return string
     */
    public function getBrokeragePer(): string
    {
        return $this->brokeragePer;
    }

    /**
     * @param string $brokeragePer
     */
    public function setBrokeragePer(string $brokeragePer): void
    {
        $this->brokeragePer = $brokeragePer;
    }

    /**
     * @return int
     */
    public function getDivisionBillId(): int
    {
        return $this->divisionBillId;
    }

    /**
     * @param int $divisionBillId
     */
    public function setDivisionBillId(int $divisionBillId): void
    {
        $this->divisionBillId = $divisionBillId;
    }

    /**
     * 校验是否绑定网商商户
     *
     * @return bool
     */
    public function checkIsBind(): bool
    {
        return Cache::remember('mybank_checkIsBindMerchant:' . $this->shopId, Carbon::tomorrow()->endOfDay(),
            function () {
                return (bool)(MybankShopBindModel::query()->where('shopId', $this->shopId)->first());
            });
    }

    /**
     * 计算佣金
     *
     * @return mixed
     */
    abstract public function calcBrokerage();


    /**
     * 更新原始订单信息
     *
     * @return mixed
     */
    abstract public function updataOrder();

}
